package com.snake.springboot.authority.service.assembler;

import com.snake.springboot.authority.api.model.AuthSysAdminModel;
import com.snake.springboot.authority.dao.mybatis.entity.AuthSysAdminDO;
import org.snake.common.code.SerialNumberGeneratorFactory;
import org.snake.common.security.MD5Util;
import org.snake.common.utils.PropertyUtils;

/**
 * 类 {@code AuthSysAdminAssembler}  <br> .
 * <p>系统信息组装器
 * 创建时间：2024/1/14 10:08
 *
 * @author huang.yj
 */
public class AuthSysAdminAssembler {

    public static AuthSysAdminDO assembleSysAdminDO(AuthSysAdminModel model, boolean isNew) throws Exception {
        AuthSysAdminDO entity = new AuthSysAdminDO();
        PropertyUtils.copyProperties(entity, model);
        if(isNew){
            entity.setPassword(MD5Util.encrypt(model.getPassword()));
            SerialNumberGeneratorFactory.buildId4Bean(entity,"sysAdminId");
        }
        return entity;
    }

    public static AuthSysAdminDO assembleSysAdminQueryDO(AuthSysAdminModel model){
        AuthSysAdminDO entity = new AuthSysAdminDO();
        PropertyUtils.copyPropertiesIfNull(entity, model);
        return entity;
    }

    public static AuthSysAdminModel assembleSysAdminModel(AuthSysAdminDO entity){
        AuthSysAdminModel model = new AuthSysAdminModel();
        PropertyUtils.copyPropertiesIfNull(model, entity);
        return model;
    }
}
